//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using System;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using EntLibContrib.Validation.Configuration.Design.Nodes;
using EntLibContrib.Validation.Configuration.Design.Properties;

namespace EntLibContrib.Validation.Configuration.Design
{
	/// <summary>
	/// Validation Command Registrar
	/// </summary>
	public class ValidationCommandRegistrar : CommandRegistrar
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="ValidationCommandRegistrar"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public ValidationCommandRegistrar(IServiceProvider serviceProvider)
			: base(serviceProvider)
		{
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Register the commands.
		/// </summary>
		public override void Register()
		{
			ConfigurationUICommand uiCommand = ConfigurationUICommand.CreateMultipleUICommand(
					base.ServiceProvider,
					Resources.AddValidationTypeFromStringCommandName,
					Resources.AddValidationTypeFromStringCommand,
					new AddTypeFromStringNodeCommand(base.ServiceProvider),
					typeof(TypeNode));

			base.AddUICommand(uiCommand, typeof(ValidationSettingsNode));

			ConfigurationUICommand testValidatorCommand = new ConfigurationUICommand(
					base.ServiceProvider,
					Resources.TestValidatorCommandName,
					Resources.TestValidatorCommand, CommandState.Enabled,
					new TestValidatorCommand(this.ServiceProvider), Shortcut.None, InsertionPoint.Action, null);

			base.AddUICommand(testValidatorCommand, typeof(ContainsCharactersValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(DateRangeValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(DomainValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(EnumConversionValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(RegexValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(RelativeDateTimeValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(StringLengthValidatorNode));
			base.AddUICommand(testValidatorCommand, typeof(TypeConversionValidatorNode));

			AddValidatorCommands(typeof(ExternallyConfiguredObjectCollectionValidatorNode), Resources.AddExternallyConfiguredObjectCollectionValidatorCommandName, Resources.AddExternallyConfiguredObjectCollectionValidatorCommand);
			AddValidatorCommands(typeof(ExternallyConfiguredObjectValidatorNode), Resources.AddExternallyConfiguredObjectValidatorNodeCommandName, Resources.AddExternallyConfiguredObjectValidatorNodeCommand);
			AddValidatorCommands(typeof(CollectionCountValidatorNode), Resources.AddCollectionCountValidatorCommandName, Resources.AddCollectionCountValidatorCommand);
			AddValidatorCommands(typeof(CompositeRuleSetValidatorNode), Resources.AddCompositeRuleSetValidatorCommandName, Resources.AddCompositeRuleSetValidatorNodeCommand);
			AddValidatorCommands(typeof(EnumDefinedValidatorNode), Resources.AddEnumDefinedValidatorCommandName, Resources.AddEnumDefinedValidatorCommand);
			AddValidatorCommands(typeof(TypeValidatorNode), Resources.AddTypeValidatorCommandName, Resources.AddTypeValidatorCommand);
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Adds the validator commands.
		/// </summary>
		/// <param name="validatorNodeType">Type of the validator node.</param>
		/// <param name="text">The text.</param>
		/// <param name="longText">The long text.</param>
		protected virtual void AddValidatorCommands(Type validatorNodeType, string text, string longText)
		{
			AddMoveUpDownCommands(validatorNodeType);

			AddDefaultCommands(validatorNodeType);

			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(FieldNode));

			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(MethodNode));

			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(PropertyNode));


			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(SelfNode));


			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(AndCompositeValidatorNode));


			AddMultipleChildNodeCommand(
					text,
					longText,
					validatorNodeType,
					typeof(OrCompositeValidatorNode));
		}
		#endregion
	}
}
